package com.persondemo.videoappliction.database;

import com.persondemo.videoappliction.bean.CollectionBean;

import org.litepal.crud.DataSupport;
import org.litepal.crud.callback.SaveCallback;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/4/10.
 */

public class CollectDao {
    public static void saveone(CollectionBean collectionBean) {
        CollectionBean collectionBean1 = new CollectionBean();
        collectionBean1 = collectionBean;
        collectionBean1.saveAsync().listen(new SaveCallback() {
            @Override
            public void onFinish(boolean success) {

            }
        });
    }
    //去重复并保存单个数据
    public static void quchong(CollectionBean collectionBean) {
        List<CollectionBean> list = new ArrayList<>();
        list = getChannels();
        if (list.size()==0){
            saveone(collectionBean);
        }
        for (int i = 0; i < list.size(); i++) {
            if (collectionBean.getVodeoid() == list.get(i).getVodeoid()) {
                DataSupport.delete(CollectionBean.class, list.get(i).getId());
            }
        }
            saveone(collectionBean);
    }

    /**
     * c查询所有
     *
     * @return
     */
    public static List<CollectionBean> getChannels() {
        return DataSupport.findAll(CollectionBean.class);
    }
    public static void delteall(){
        DataSupport.deleteAll(CollectionBean.class);
    }
}
